
var homeInfo = null;
var Popularize = {
    init:function(){
        this.getData(1);
    },
    eventLisenter:function(){
    	var that = this;
        $(".intenthtml").click(function(){
            window.location.href=$(this).attr("href");
        });
		$(".basehtml").scroll(function(e){
			var scrollHeight=$(".basehtml")[0].scrollHeight;
			var height = $(window).height();
			var scrollTop= $(".basehtml").scrollTop();
			if(homeInfo.length == 10){
				if(scrollTop == scrollHeight-height){
                    // $(".content .p").text("正在加载");
                    that.getData(++homeInfo.pageNo);
				}
			}else{
				$(".content .p").text("-没有更多-");
			}
        });
    },
    getData:function(pageNo){
		// $(".p").text("正在加载");
        new AjaxRequest({
            type: "post",
            url:apiService.mySuitSpreadList,
            param: JSON.stringify({pageNo:pageNo,limit:10}),
            callBack:function(res){
                if(res.code==302){
                    window.location.href= res.url;
                }else if(res.success){
                    $(".spread").text(res.payload.spreadCount);
                    $(".award").text(res.payload.awardedCount);
                    var data = res.payload.items;
                    alert(pageNo+"======="+data.length);
                    homeInfo = data;
                    homeInfo.pageNo = pageNo;
                    if(data.length<10){
                        $(".content .p").text("-没有更多-");
                    }else{
                        $(".content .p").text("-加载更多-");
                    }
                    for (let i = 0; i < data.length; i++) {
                        buildDom(data[i],".content");
                    }
                }else{
                    alert(res.message);
                }
            },
            failBack: function(){
				$(".p").text("-没有更多-");
            }
        });
    }
}

function oncilk(dom){
    window.location.href=$(dom).attr("href");
}

function buildDom(data,id){
    var imgurl = "";
    if (data.type==1){
        imgurl="../../img/popullarize/gyshare.png";
    }else{
        imgurl="../../img/popullarize/gdshare.png";
    }
    var dom = `<div class="jl-item flexs-pace-between">
                <div class="flexs-center tg-i-l">
                    <img src="${imgurl}"/>
                    <div class="tg-tixt" style="margin-left:0.5rem">
                        <p style="font-weight: bold">推广时间 : ${data.spreadDate}</p>
                        <p style="font-weight: bold">会话对象 : ${data.subChannel}</p>
                        <p>访问次数 : ${data.accessCount}</p>
                        <p>访问用户 : ${data.accessUserCount}</p>
                    </div>
                </div>
                <div class="flexs-pace-between-col tg-i-r">
                    <p class="sharetype">${data.channel}</p>
                    <p class="money">+${data.awardAmt}元</p>
                </div>
            </div>`;
    $(id+" .c").append(dom);
}